/*
 * @Description: 
 * @Author: ljy
 * @Date: 2021-12-02 16:47:37
 * @LastEditors: ljy
 * @LastEditTime: 2021-12-02 17:59:00
 */
const e = require('express')
const pool = require('./pool')

function findAll(fun) {
    pool.myQuery("select * from t_comment", [], (result) => {
        fun(result)
    })
}

function deleteById(id, fun) {
    pool.myQuery("delete from t_comment where id=?", [id], (result) => {
        fun(result)
    })
}

function add(obj, fun) {
    if (obj.id) {
        pool.myQuery("update t_comment set user_id=?,movie_id=?,sc=?,content=?,approve=?,calc_time=? where id=?", [obj.user_id, obj.movie_id, obj.sc, obj.content, obj.approve, obj.calc_time, obj.id], (result) => {
            fun(result)
        })
    } else {
        pool.myQuery("insert into t_comment(user_id,movie_id,sc,content,approve,calc_time) value(?,?,?,?,?,?)", [obj.user_id, obj.movie_id, obj.sc, obj.content, obj.approve, obj.calc_time], (result) => {
            fun(result)
        })
    }

}

module.exports = { findAll, deleteById, add }